var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ifShowTips: true,
    userVo: {}, //个人资料信息
    userId: "",
    auditStatusText: "",//auditStatus:1未认证2认证失败3认证成功
    wxType: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({ wxType: app.globalData.wxType });
    // wx.getStorage({
    //   key: 'userId',
    //   success: function (res) {
    //     console.log("111111",res.data); 
    //     that.setData({userId : res.data});
    //     console.log("2222",that.data.userId);
    //     var userId = res.data;
    // wx.request({
    //   method: "POST",
    //   url: 'https://www.zaishengwang.com/wx/toHomeUser.do',
    //   dataType: 'json',
    //   header: {
    //     'content-type': 'application/x-www-form-urlencoded',
    //   },
    //   data: {
    //     id: that.data.userId,
    //   },
    //   success: function (res) {
    //     console.log("111", res.data);
    //     that.setData({ userVo: res.data.userVo });
    //   },
    //   fail: function (error) {
    //     console.log(error);
    //   }
    //})
    //},

    // });
    if (app.globalData.userId) {
      that.onMineInfo();
      that.setData({
        ifShowTips: true
      });
    } else {
      that.setData({
        ifShowTips: false
      });
    }
  },

  onMineInfo: function() {
    var that = this;
    wx.request({
      method: "POST",
      url: 'https://www.zaishengwang.com/wx/toHomeUser.do',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        id: app.globalData.userId,
      },
      success: function(res) {
        that.setData({
          userVo: res.data.userVo
        });
        if (res.data.userVo.auditStatus == 1) {
          that.setData({
            auditStatusText: "未认证"
          });
        } else if (res.data.userVo.auditStatus == 2) {
          that.setData({
            auditStatusText: "认证失败"
          });
        } else if (res.data.userVo.auditStatus == 3) {
          that.setData({
            auditStatusText: "认证成功"
          });
        }

      },
      fail: function(error) {
        console.log(error);
      }
    })
  },

  //个人设置中心
  goSetting: function() {
    wx.navigateTo({
      url: 'accountSetting',
    })
  },

  //我的余额
  goMyBalance: function () {
    wx.navigateTo({
      url: 'myBalance',
    })
  },
  

  //意见反馈
  goSuggestion: function() {
    wx.navigateTo({
      url: 'suggestion',
    })
  },

  //销货订单
  goSalersOrder: function() {
    wx.navigateTo({
      url: 'salersOrder',
    })
  },

  //对账单
  goStatement: function() {
    wx.navigateTo({
      url: 'statement',
    })
  },

  //账户设置
  goAccountSetting: function() {
    var that = this;
    //var detailAddress = that.data.userVo.province + ' ' +  that.data.userVo.city + ' ' + that.data.userVo.area + ' ' + that.data.userVo.address
    wx.navigateTo({
      // url: 'accountSetting?contacts=' + that.data.userVo.contacts + '&telephone=' + that.data.userVo.telephone + '&detailAddress=' + detailAddress,
      url: 'accountSetting?contacts',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  //我要销货
  goSales: function() {
    wx.showModal({
      // title: '提示',
      content: '确认销货，卡车司机上门回收',
      confirmText: '确认',
      confirmColor: '#56BDE0',
      success: function(res) {
        if (res.confirm) {
          console.log('用户点击确定');
          console.log(res.confirm);
          wx.request({
            method: "POST",
            url: 'https://www.zaishengwang.com/wx/toSellthe.do',
            dataType: 'json',
            header: {
              'content-type': 'application/x-www-form-urlencoded',
            },
            data: {
              userId: app.globalData.userId,
            },
            success: function (res) {
              if(res.data.msg=="1"){
                wx.showModal({
                  title: '下单成功',
                  content: '已提交订单，正在派单中',
                  confirmColor: '#56BDE0',
                  showCancel: false,
                })
              } 
            },
            fail: function (error) {
              console.log(error);
            }
          })

        } else if (res.cancel) {
          console.log('用户点击取消');
          console.log(res.cancel);
        }
      }
    })
  },

  gosupplyAndDemand: function (){
    wx.navigateTo({
      url: 'supplyAndDemand',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
  
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '绿大侠',
      path: '/pages/home/home?userId=' + app.globalData.userId ,
      
    }
  }                                                                                                                                                                                
  
})